﻿using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;

namespace Postnuclear.Collections
  {
  /// <summary>
  /// The extension methods for the <see cref="INotifyCollectionChanged{T}"/> and <see cref="ObservableItemEventArgs{T}"/>.
  /// </summary>  
  public static partial class ExtensionMethods
    {
    #region Public

    /// <summary>
    /// Raises the specified event with specified value.
    /// </summary>
    /// <typeparam name="TSender">The type of the sender object.</typeparam>
    /// <typeparam name="T">The type of the elements in the collection.</typeparam>
    /// <param name="handler">The handler.</param>
    /// <param name="sender">The sender.</param>
    /// <param name="item">The added/removed item.</param>
    /// <param name="index">The items index.</param>
    [DebuggerHidden]
    public static void Raise<TSender, T>(this EventHandler<ObservableItemEventArgs<T>> handler, TSender sender, T item, int index)
      {
      Contract.Requires<ArgumentNullException>(sender != null);
      Contract.Requires<ArgumentOutOfRangeException>(index >= 0);

      handler.Raise(sender, new ObservableItemEventArgs<T>(item, index));
      }

    #endregion
    }
  }